package com.bootdo.system.dao;

import com.bootdo.system.domain.SettingDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SettingMapper {

    /**
     * 根据id查找
     * @param id
     * @return
     */
    @Select("select * from sys_settings where id=#{id}")
    SettingDO get(Integer id);

    /**
     * 根据key查找
     * @param key
     * @return
     */
    @Select("select * from sys_settings where key=#{key}")
    SettingDO unique(String key);

    /**
     * 查询所有
     * @return
     */
    @Select("select * from sys_settings")
    List<SettingDO> listAll();

    /**
     * 更新
     * @param entity
     * @return
     */
    @Update("update sys_settings set value=#{value}, memo=#{memo} where id=#{id}")
    int update(SettingDO entity);

    /**
     * 根据key启用
     * @param key
     * @return
     */
    @Update("update sys_settings set is_enable=1 where key=#{key}")
    int enable(String key);

    /**
     * 根据id启用
     * @param id
     * @return
     */
    @Update("update sys_settings set is_enable=1 where id=#{id}")
    int enableById(Integer id);

    /**
     * 根据key禁用
     * @param key
     * @return
     */
    @Update("update sys_settings set is_enable=0 where key=#{key}")
    int disable(String key);

    /**
     * 根据id禁用
     * @param id
     * @return
     */
    @Update("update sys_settings set is_enable=0 where id=#{id}")
    int disableById(Integer id);
}
